<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8">
		<title>Hello MUI</title>
		<meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1,user-scalable=no">
		<meta name="apple-mobile-web-app-capable" content="yes">
		<meta name="apple-mobile-web-app-status-bar-style" content="black">
		<link rel="import" href="../header.html" id="page1">
		<!--标准mui.css-->
		<!--App自定义的css-->
		<!-- <link rel="stylesheet" type="text/css" href="../css/app.css" /> -->
1		<link href="../../css/mui.picker.css" rel="stylesheet" />
		<link href="../../css/mui.poppicker.css" rel="stylesheet" />
		<style>
			h5 {
				margin: 5px 7px;
			}
		</style>
		<style>
			.mui-btn {
				font-size: 16px;
				padding: 8px;
				margin: 3px;
			}
			h5.mui-content-padded {
				margin-left: 3px;
				margin-top: 20px !important;
			}
			h5.mui-content-padded:first-child {
				margin-top: 12px !important;
			}
			.ui-alert {
				text-align: center;
				padding: 20px 10px;
				font-size: 16px;
			}
		</style>
	</head>

	<body>
		<header class="mui-bar mui-bar-nav">
			<a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
			<h1 class="mui-title">新建巡检</h1>
		</header>
		<div class="mui-content" id="rrapp">
			<div v-show="!childtk" class="mui-content-padded " style="margin: 5px;">
				  <div class="mui-input-row mui-content-padded">
				  	<label>基地</label>
				  	<input id='showjdPicker' class="mui-input-clear mui-input" v-model="bussinspectiontask.deptIdname"  type="text" placeholder="设备点"  readonly="readonly"></input>
				  </div>
				  <div class="mui-input-row mui-content-padded">
				  	<label>田块</label>
				  	<input  @click="gettk"  v-model="bussinspectiontask.checkedNames"  type="text" placeholder="选择和查看田块"  readonly="readonly"></input>
				  </div>
					<div class="mui-input-row mui-content-padded">
					<label>巡检人</label>
					<input id='showUserPicker2' v-model="bussinspectiontask.handlername"   class="" type="text" placeholder="指派人" readonly="readonly"></input>
					</div>
					<div class="mui-input-row mui-content-padded">
						<label>任务名称</label>
					<input  v-model="bussinspectiontask.taskName" class="" type="text" placeholder="名称" ></input>
					</div>
					<div class="mui-input-row" style="margin: 10px 5px;">
						<label>巡检内容</label>
						<textarea v-model="bussinspectiontask.taskContent"  id="textarea" rows="5" placeholder="内容"></textarea>
					</div>
					
					<div class="mui-button-row">
						<button type="button" class="mui-btn mui-btn-primary" @click="save">确认</button>&nbsp;&nbsp;
						<button type="button" class="mui-btn mui-btn-danger" @click="fhxj">返回</button>
					</div>
			</div>
			
			<div v-show="childtk" class="mui-card">
				<ul class="mui-table-view">
					<li v-for="item in tkList" class="mui-table-view-cell mui-checkbox mui-left">
						<input  :value="item.id" name="ckname" type="checkbox" v-model="checkedNames">{{item.name}}
					</li>
				</ul>
				<div class="mui-button-row" style="margin-bottom: 0.625rem;">
					<button type="button"  class="mui-btn mui-btn-danger" @click="fh">返回</button>
				</div>
			</div>
			
			
		</div>
		<!--<script src="../js/mui.picker.min.js"></script>-->
		<script src="../../js/mui.picker.js"></script>
		<script src="../../js/mui.poppicker.js"></script>
		<script src="../../js/city.data.js" type="text/javascript" charset="utf-8"></script>
		<script src="../../js/city.data-3.js" type="text/javascript" charset="utf-8"></script>
		<script>
			(function($, doc) {
				$.init();
					
				
				$.ready(function() {
					
				});
			})(mui, document);
			
			
			var vm = new Vue({
				el:'#rrapp',
				data:{
					showList: true,
					title: null,
					insIndetailsugtion: {},
					childtk:false,
					tkList: [], //田块集合
					checkedNames: [],
					jd:'',
					bussinspectiontask: {
					  id: '',
					  farmlandInfoIds: '',
					  resultFileIds: '',
					  parentName:'',
					  handler: '',
					  inspectionPlanId: '',
					  deptId: '',
					  deptName:'',
					  businessNum: '',
					  taskName: '',
					  taskContent: '',
					  startTime: '',
					  planTime: '',
					  resultStatus: '',
					  resultContent: '',
					  status: '',
					  sourceType: '',
					  createId: '',
					  createName: '',
					  createTime: '',
					  updateId: '',
					  updateTime: '',
					  updateName: '',
					  version: '',
					  gcFlag: '',
					  planTime: '',
					 	
					 },
				},
				methods: {
					getm: function () {
						console.log(this.bussinspectiontask.deptId)
						//showjdPicker
						mui.getJSON(baseUrl+'/sys/dept/select3',{'type':1},function(data){
							console.log(data)
							var gdata = [];
							if(data.deptList!=null){
							for (var i = 0; i < data.deptList.length; i++) {
								var getlist = data.deptList[i];
								var b1 = getlist.id;
								var b2 = getlist.name;
								var gb = {"value":b1,"text":b2};
								gdata.push(gb);
								var _getParam = function(obj, param) {
									return obj[param] || '';
								};
								//普通示例
								var userPicker = new mui.PopPicker();
								userPicker.setData(
									gdata
								);
								var showUserPickerButton = document.getElementById('showjdPicker');
								var userResult = document.getElementById('showjdPicker');
								showUserPickerButton.addEventListener('click', function(event) {
									if(vm.bussinspectiontask.deptId!=null&&vm.bussinspectiontask.deptId!=""){
										userPicker.pickers[0].setSelectedValue(vm.bussinspectiontask.deptId)
									}	
									userPicker.show(function(items) {
										vm.bussinspectiontask.deptIdname = items[0].text 
										vm.bussinspectiontask.deptId = items[0].value
										vm.jd = items[0].value
										vm.checkedNames = [];
										vm.getTkList();
									});
								}, false);
							}
							}
						});
						//222
						mui.ajax(baseUrl+'/sys/user/list2',{
							data:{
								'page': 1,
								'limit': 999,
							},
							dataType:'json',//服务器返回json格式数据
							async: false,
							type:'get',//HTTP请求类型
							//headers:{'Content-Type':'application/json'},	              
							success:function(data){
								var gdata = [];
								for (var i = 0; i < data.page.list.length; i++) {
									var getlist = data.page.list[i];
									/**
									 * 获取对象属性的值
									 * 主要用于过滤三级联动中，可能出现的最低级的数据不存在的情况，实际开发中需要注意这一点；
									 * @param {Object} obj 对象
									 * @param {String} param 属性名
									 */
									var b1 = getlist.id;
									var b2 = getlist.name;
									var gb = {"value":b1,"text":b2};
									gdata.push(gb);
									var _getParam = function(obj, param) {
										return obj[param] || '';
									};
									//普通示例
									var userPicker = new mui.PopPicker();
									
									
									userPicker.setData(
									gdata
									);
									var showUserPickerButton = document.getElementById('showUserPicker2');
									var userResult = document.getElementById('showUserPicker2');
									showUserPickerButton.addEventListener('tap', function(event) {
										if(vm.bussinspectiontask.handler!=null&&vm.bussinspectiontask.handler!=""){
											userPicker.pickers[0].setSelectedValue(vm.bussinspectiontask.handler)
										}	
										userPicker.show(function(items) {
											vm.bussinspectiontask.handlername = items[0].text 
											vm.bussinspectiontask.handler = items[0].value
										});
									}, false);
								}
							}
						});
						//333
						console.log(T.p("gid"))
						var id = T.p("gid");
						if(id!=null&&id!=null){
							 mui.get(baseUrl+"/buss/bussinspectiontask/info/"+id,function(data,status){
								console.log(data.bussInspectionTask)
								vm.bussinspectiontask = data.bussInspectionTask
								
								var str = vm.bussinspectiontask.farmlandInfoIds;
								if(str!=null&&str!=''){
									vm.checkedNames = str.split(','); // [ab, c, de]
								}
								console.log(vm.checkedNames)
								
								vm.jd = data.bussInspectionTask.deptId;
								vm.getTkList();
							});
						}
						
					},
					gettk:function(id){
						vm.childtk = true
					},
					save : function(){
						if(vm.checkedNames.length>0){
							var c = vm.checkedNames.join(','); //abcde
							vm.bussinspectiontask.farmlandInfoIds = c
						}
						
						
						
						var url = vm.bussinspectiontask.id == "" ? "/buss/bussinspectiontask/save" : "/buss/bussinspectiontask/update";
						if(vm.bussinspectiontask.id == null || vm.bussinspectiontask.id == ""){
							vm.bussinspectiontask.status = 0
						}
						
						mui.ajax(baseUrl+url,{
							data:JSON.stringify(vm.bussinspectiontask),
							async: false,
							contentType: "application/json",
							type:'post',//HTTP请求类型
							success:function(data){
								if(data.code == 0){
									mui.toast('添加成功', {
										duration: 'long',
										type: 'div'
									})
									mui.openWindow({
									url: "xunjian.html",
									createNew:true
									});
									
								}else{
									mui.toast('添加失败', {
										duration: 'long',
										type: 'div'
									})
								}
								
							},error: function(xhr, type, errorThrown) {
								//异常处理；
								mui.toast('添加失败', {
									duration: 'long',
									type: 'div'
								})
							}
					})
					},
					fh:function(){
					   console.log('返回')
					  // mui.back()		
					   vm.childtk = false
 					},
					fhxj(){
						mui.openWindow({
						url: "xunjian.html",
						createNew:true
						});
					},
					 getTkList: function() { //田块数据集
						var self = this;
						self.showTkList = true;
						mui.ajax(baseUrl + '/buss/bussfarmlandinfo/list', {
							data: {
								//'tkNum': self.tkNum,
								'jd' : self.jd
							},
							dataType: 'json', //服务器返回json格式数据
							type: 'get', //HTTP请求类型
							success: function(data) {
								//获得服务器响应
								
								
								self.tkList = data.page.list;
								
							}
						});
					 },
				},
				mounted:function(){
					this.getm();
					this.getTkList();
					// mui.init({  
					// 	subpages: [{  
					// 		url: 'gettk.html', //子页面HTML地址，支持本地地址和网络地址  
					// 		id: 'gettk', //子页面标志  
					// 		styles: {  
					// 			//top: subpage - top - position, //子页面顶部位置  
					// 			//bottom: subpage - bottom - position, //子页面底部位置  
					// 			//width: subpage - width, //子页面宽度，默认为100%  
					// 			//height: subpage - height, //子页面高度，默认为100%  
					// 		},  
					// 		extras: {
					// 			
					// 		} //额外扩展参数  
					// 	}]  
					// }); 
				}
			});
			

		</script>
	</body>

</html>